﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ext.Net;
using System.Web.Routing;
using FreedomERP.Filter;
using FreedomERP.Comm;

namespace FreedomERP.Controllers
{
    [CheckSessionFilterAttribute]
    public class MenuController : Controller
    {
        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);
        }

        public TreeNodeCollection LoadCurUserMenu()
        {
            string currAccountOrgunitFName = BaseController.GetCurrLoginAccountOrgunitFName();

            TreeNodeCollection nodes = new TreeNodeCollection(false);

            TreeNode AccountManagerNode = new TreeNode();
            AccountManagerNode.NodeID = "";
            AccountManagerNode.Text = "帐号管理";
            AccountManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            nodes.Add(AccountManagerNode);

            TreeNode AccountListNode = new TreeNode();
            AccountListNode.NodeID = "/Account/AccountIndex/";
            AccountListNode.Text = "帐号列表";
            AccountListNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            AccountManagerNode.Nodes.Add(AccountListNode);

            TreeNode ModifyPasswordNode = new TreeNode();
            ModifyPasswordNode.NodeID = "/Account/AccountPassword/";
            ModifyPasswordNode.Text = "修改密码";
            ModifyPasswordNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            AccountManagerNode.Nodes.Add(ModifyPasswordNode);

            TreeNode SendOrderManagerNode = new TreeNode();
            SendOrderManagerNode.NodeID = "";
            SendOrderManagerNode.Text = "送货单管理";
            SendOrderManagerNode.Qtip = "";
            SendOrderManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            nodes.Add(SendOrderManagerNode);

            if (currAccountOrgunitFName != null && currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_LC))
            {
                TreeNode AddSendOrderNode = new TreeNode();
                AddSendOrderNode.NodeID = "/SendOrder/AddOrder/";
                AddSendOrderNode.Text = "添加送货单";
                AddSendOrderNode.Qtip = "";
                AddSendOrderNode.Leaf = true;
                AddSendOrderNode.CustomAttributes.Add(new ConfigItem("allowMulti", "true", ParameterMode.Value));
                SendOrderManagerNode.Nodes.Add(AddSendOrderNode);

                TreeNode SendOrderListNode = new TreeNode();
                SendOrderListNode.NodeID = "/SendOrder/OrderList/";
                SendOrderListNode.Text = "送货单列表";
                SendOrderListNode.Qtip = "";
                SendOrderListNode.Leaf = true;
                SendOrderListNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                SendOrderManagerNode.Nodes.Add(SendOrderListNode);
            }
            else if (currAccountOrgunitFName != null && currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_GL))
            {

                TreeNode AddSendOrderGeLiNode = new TreeNode();
                AddSendOrderGeLiNode.NodeID = "/SendOrder/AddOrderGeLi/";
                AddSendOrderGeLiNode.Text = "添加送货单";
                AddSendOrderGeLiNode.Qtip = "";
                AddSendOrderGeLiNode.Leaf = true;
                AddSendOrderGeLiNode.CustomAttributes.Add(new ConfigItem("allowMulti", "true", ParameterMode.Value));
                SendOrderManagerNode.Nodes.Add(AddSendOrderGeLiNode);

                TreeNode SendOrderListGeLiNode = new TreeNode();
                SendOrderListGeLiNode.NodeID = "/SendOrder/OrderListGeLi/";
                SendOrderListGeLiNode.Text = "送货单列表";
                SendOrderListGeLiNode.Qtip = "";
                SendOrderListGeLiNode.Leaf = true;
                SendOrderListGeLiNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                SendOrderManagerNode.Nodes.Add(SendOrderListGeLiNode);
            }

            /**
            TreeNode ShortageOrderManagerNode = new TreeNode();
            ShortageOrderManagerNode.NodeID = "";
            ShortageOrderManagerNode.Text = "缺货单管理";
            ShortageOrderManagerNode.Qtip = "";
            ShortageOrderManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            nodes.Add(ShortageOrderManagerNode);

            TreeNode ShortageOrderListNode = new TreeNode();
            ShortageOrderListNode.NodeID = "/ShortageOrder/ShortageOrderIndex/";
            ShortageOrderListNode.Text = "缺货单列表";
            ShortageOrderListNode.Qtip = "";
            ShortageOrderListNode.Leaf = true;
            ShortageOrderListNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            ShortageOrderManagerNode.Nodes.Add(ShortageOrderListNode);
            */

            TreeNode ProductManagerNode = new TreeNode();
            ProductManagerNode.NodeID = "";
            ProductManagerNode.Text = "产品管理";
            ProductManagerNode.Qtip = "";
            ProductManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
            nodes.Add(ProductManagerNode);



            if (currAccountOrgunitFName != null && currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_GL))
            {
                TreeNode CreatProductNode = new TreeNode();
                CreatProductNode.NodeID = "/Product/ProductIndexGeLi/";
                CreatProductNode.Text = "产品管理";
                CreatProductNode.Qtip = "";
                CreatProductNode.Leaf = true;
                CreatProductNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(CreatProductNode);

                TreeNode CreatProdCateNode = new TreeNode();
                CreatProdCateNode.NodeID = "/ProdCategory/ProdCategoryIndexGeli/";
                CreatProdCateNode.Text = "产品规格管理";
                CreatProdCateNode.Qtip = "";
                CreatProdCateNode.Leaf = true;
                CreatProdCateNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(CreatProdCateNode);

                TreeNode CreatProdUnitNode = new TreeNode();
                CreatProdUnitNode.NodeID = "/ProdCategory/ProdCategoryUnitIndex/";
                CreatProdUnitNode.Text = "产品单位管理";
                CreatProdUnitNode.Qtip = "";
                CreatProdUnitNode.Leaf = true;
                CreatProdUnitNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(CreatProdUnitNode);

                TreeNode OutInCountNode = new TreeNode();
                OutInCountNode.NodeID = "/Product/ProductOutInCount/";
                OutInCountNode.Text = "产品进出货统计";
                OutInCountNode.Qtip = "";
                OutInCountNode.Leaf = true;
                OutInCountNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(OutInCountNode);
            }
            else
            {
                TreeNode CreatProductNode = new TreeNode();
                CreatProductNode.NodeID = "/Product/ProductIndex/";
                CreatProductNode.Text = "产品管理";
                CreatProductNode.Qtip = "";
                CreatProductNode.Leaf = true;
                CreatProductNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(CreatProductNode);

                TreeNode CreatProdCateNode = new TreeNode();
                CreatProdCateNode.NodeID = "/ProdCategory/ProdCategoryIndex/";
                CreatProdCateNode.Text = "产品规格管理";
                CreatProdCateNode.Qtip = "";
                CreatProdCateNode.Leaf = true;
                CreatProdCateNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ProductManagerNode.Nodes.Add(CreatProdCateNode);
            }

            if (currAccountOrgunitFName != null && currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_GL))
            {
                TreeNode ReceiveOrderManagerNode = new TreeNode();
                ReceiveOrderManagerNode.NodeID = "";
                ReceiveOrderManagerNode.Text = "收货单管理";
                ReceiveOrderManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                nodes.Add(ReceiveOrderManagerNode);

                TreeNode ReceiveOrderListNode = new TreeNode();
                ReceiveOrderListNode.NodeID = "/ReceiveOrder/ReceiveOrderIndex/";
                ReceiveOrderListNode.Text = "收货单列表";
                ReceiveOrderListNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                ReceiveOrderManagerNode.Nodes.Add(ReceiveOrderListNode);
            }

            if (currAccountOrgunitFName == null || !currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_GL))
            {
                TreeNode CustomerManagerNode = new TreeNode();
                CustomerManagerNode.NodeID = "";
                CustomerManagerNode.Text = "客户管理";
                CustomerManagerNode.Qtip = "";
                CustomerManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                nodes.Add(CustomerManagerNode);

                TreeNode CustomerInfoNode = new TreeNode();
                CustomerInfoNode.NodeID = "/Customer/CustomerIndex/";
                CustomerInfoNode.Text = "客户信息管理";
                CustomerInfoNode.Qtip = "";
                CustomerInfoNode.Leaf = true;
                CustomerInfoNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                CustomerManagerNode.Nodes.Add(CustomerInfoNode);
            }

            if (currAccountOrgunitFName != null && currAccountOrgunitFName.Equals(ConstData.ORGUNIT_NAME_GL))
            {
                TreeNode SaleOrderManagerNode = new TreeNode();
                SaleOrderManagerNode.NodeID = "";
                SaleOrderManagerNode.Text = "销售管理";
                SaleOrderManagerNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                nodes.Add(SaleOrderManagerNode);

                TreeNode SendScanNode = new TreeNode();
                SendScanNode.NodeID = "/SaleOrder/SendBarcodeScan/";
                SendScanNode.Text = "出货扫描";
                SendScanNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                SaleOrderManagerNode.Nodes.Add(SendScanNode);

                TreeNode InstallScanNode = new TreeNode();
                InstallScanNode.NodeID = "/SaleOrder/InstallBarcodeScan/";
                InstallScanNode.Text = "安装扫描";
                InstallScanNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                SaleOrderManagerNode.Nodes.Add(InstallScanNode);

                TreeNode SaleOrderListNode = new TreeNode();
                SaleOrderListNode.NodeID = "/SaleOrder/SaleOrderIndex/";
                SaleOrderListNode.Text = "销售订单列表";
                SaleOrderListNode.CustomAttributes.Add(new ConfigItem("allowMulti", "false", ParameterMode.Value));
                SaleOrderManagerNode.Nodes.Add(SaleOrderListNode);
            }

            return nodes;
        }
    }
}
